package com.woniuxy.creditsystem.common.mapper;

import com.woniuxy.creditsystem.common.bean.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;


/**
 * @author ：luoyue
 * @date ：Created in 2020/12/11
 * @description：房产信息mapper
 * @modified By：
 * @version: 1.0v
 */
@Mapper
public interface HouseMapper {



    /**
     * 新增房产信息
     *
     * @param houseInfo
     * @return 受影响的行数
     * @author luoyue
     */
    @Options(
            useGeneratedKeys = true,
            keyProperty = "h.id"
    )
    @Insert("insert into house_property_info " +
            "(buy_time,purchase_price,build_date,land_number,license,detail_address,housing_type,covered_area,property_right_number,deed_tax_number,house_address,fk_customer_id)" +
            " values(#{h.buyTime},#{h.purchasePrice},#{h.buildDate},#{h.landNumber},#{h.license},#{h.detailAddress},#{h.housingType},#{h.coveredArea},#{h.propertyRightNumber},#{h.deedTaxNumber},#{h.houseAddress},#{h.customerInfo.id})")
    int saveHouseInfo(@Param("h") HouseInfo houseInfo);





    /**
     * 根据ID查询房产信息
     * @param id
     * @return  返回受影响得行
     * @author luoyue
     */
    @Results({
            @Result(id=true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "buyTime",column = "buyTime",javaType = Date.class),
            @Result(property = "purchasePrice",column = "car_model",javaType = Double.class),
            @Result(property = "buildDate",column = "vehicle_license",javaType = String.class),

            @Result(property = "landNumber",column = "frame_number",javaType = String.class),
            @Result(property = "license",column = "engine_number",javaType = String.class),
            @Result(property = "detailAddress",column = "car_color",javaType = String.class),

            @Result(property = "housingType",column = "vehicle_years",javaType = long.class),
            @Result(property = "coveredArea",column = "bare_car_price",javaType = Double.class),
            @Result(property = "propertyRightNumber",column = "buy_time",javaType = String.class),

            @Result(property = "deedTaxNumber",column = "car_license_time",javaType = String.class),
            @Result(property = "houseAddress",column = "driven_distance",javaType = String.class),

            @Result(property = "customerInfo",column = "fk_customer_id",javaType = CustomerInfo.class,one =
            @One(select = "com.woniuxy.creditsystem.common.mapper.CustomerMapper.getOneById",fetchType = FetchType.LAZY)),
    })
    @Select("select * from house_property_info where id = #{id}")
    HouseInfo getOneById(Long id);


    /**
     * 根据参数进行模糊分页查询
     * @param houseFind
     * @return 返回查询结果房产列表
     * @Author luoyue
     */
    List<HouseInfo> findAllByParams(@Param("hf") HouseFind houseFind);

    /**
     * 删除房产信息
     * @param id
     * @return 受影响的行数
     */

    @Delete("delete from house_property_info where id = #{id}")
    int deleteHouse(@Param("id")Long id);



    /**
     * 修改房产信息
     *v.
     * @param houseInfo
     * @return 受影响的行数
     */
    @Update("<script>" +
            "update house_property_info" +
            "<set>" +
            "<if test='h.housingType != null'>" +
            " housing_type = #{h.housingType}," +
            "</if>" +
            "<if test='h.houseAddress != null'>" +
            " house_address = #{h.houseAddress}," +
            "</if>" +
            "</set>" +
            "where id = #{h.id}" +
            "</script>")
    int updateHouse(@Param("h") HouseInfo houseInfo);

}
